package com.ruoyi.web.controller.ydz;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.OtherNews;
import com.ruoyi.web.service.IOtherNewsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 其他新闻类Controller
 * 
 * @author drx
 * @date 2024-03-20
 */
@Controller
@RequestMapping({"/ydz/otherNews","/api/otherNews"})
@Api(tags = "其他新闻类")
public class OtherNewsController extends BaseController
{
    private String prefix = "ydz/otherNews";

    @Autowired
    private IOtherNewsService otherNewsService;

    @RequiresPermissions("ydz:ycwz:view")
    @GetMapping("/ycwz")
    public String ycwz(ModelMap mmap)
    {
        mmap.put("classify", "1");
        return prefix + "/otherNews";
    }

    @RequiresPermissions("ydz:yyqy:view")
    @GetMapping("/yyqy")
    public String yyqy(ModelMap mmap)
    {
        mmap.put("classify", "2");
        return prefix + "/otherNews";
    }

    @RequiresPermissions("ydz:aqyy:view")
    @GetMapping("/aqyy")
    public String aqyy(ModelMap mmap)
    {
        mmap.put("classify", "3");
        return prefix + "/otherNews";
    }

    @RequiresPermissions("ydz:jkhl:view")
    @GetMapping("/jkhl")
    public String jkhl(ModelMap mmap)
    {
        mmap.put("classify", "4");
        return prefix + "/otherNews";
    }

    /**
     * 查询其他新闻类列表
     */
    @RequiresPermissions("ydz:otherNews:list")
    @PostMapping("/list")
    @ResponseBody
    @ApiOperation("查询其他新闻类列表")
    public TableDataInfo list(OtherNews otherNews)
    {
        startPage();
        List<OtherNews> list = otherNewsService.selectOtherNewsList(otherNews);
        return getDataTable(list);
    }

    /**
     * 查询其他新闻类列表
     */
    @PostMapping("/selectOtherNewsList")
    @ResponseBody
    @ApiOperation("查询其他新闻类列表")
    public TableDataInfo selectOtherNewsList(@RequestBody OtherNews otherNews)
    {
        startPage();
        List<OtherNews> list = otherNewsService.selectOtherNewsList(otherNews);
        return getDataTable(list);
    }

    /**
     * 导出其他新闻类列表
     */
    @RequiresPermissions("ydz:otherNews:export")
    @Log(title = "其他新闻类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    @ApiOperation("导出其他新闻类列表")
    public AjaxResult export(OtherNews otherNews)
    {
        List<OtherNews> list = otherNewsService.selectOtherNewsList(otherNews);
        ExcelUtil<OtherNews> util = new ExcelUtil<OtherNews>(OtherNews.class);
        return util.exportExcel(list, "其他新闻类数据");
    }

    /**
     * 新增其他新闻类
     */
    @GetMapping("/add/{classify}")
    @ApiOperation("新增其他新闻类")
    public String add(@PathVariable("classify") String classify, ModelMap mmap)
    {
        mmap.put("classify", classify);
        return prefix + "/add";
    }

    /**
     * 新增保存其他新闻类
     */
    @ApiOperation("新增保存其他新闻类")
    @RequiresPermissions("ydz:otherNews:add")
    @Log(title = "其他新闻类", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OtherNews otherNews)
    {
        return toAjax(otherNewsService.insertOtherNews(otherNews));
    }

    /**
     * 修改其他新闻类
     */
    @ApiOperation("修改其他新闻类")
    @RequiresPermissions("ydz:otherNews:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        OtherNews otherNews = otherNewsService.selectOtherNewsById(id);
        mmap.put("otherNews", otherNews);
        return prefix + "/edit";
    }

    /**
     * 修改保存其他新闻类
     */
    @ApiOperation("修改保存其他新闻类")
    @RequiresPermissions("ydz:otherNews:edit")
    @Log(title = "其他新闻类", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OtherNews otherNews)
    {
        return toAjax(otherNewsService.updateOtherNews(otherNews));
    }

    /**
     * 删除其他新闻类
     */
    @ApiOperation("删除其他新闻类")
    @RequiresPermissions("ydz:otherNews:remove")
    @Log(title = "其他新闻类", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(otherNewsService.deleteOtherNewsByIds(ids));
    }

    /**
     * 修改保存新闻管理
     */
    @ApiOperation("修改保存新闻管理")
    @RequiresPermissions("ydz:otherNews:edit")
    @Log(title = "新闻管理", businessType = BusinessType.UPDATE)
    @PostMapping("/editState")
    @ResponseBody
    public AjaxResult editState(@RequestBody OtherNews otherNews)
    {
        return toAjax(otherNewsService.updateOtherNews(otherNews));
    }

    /**
     * 获取新闻详情-前端调用
     */

    @ApiOperation("获取新闻详情-前端调用")
    @GetMapping("/get/{id}")
    @ResponseBody
    public AjaxResult get(@PathVariable("id") Long id)
    {
        return otherNewsService.getOtherNewsById(id);
    }

    /**
     * 其他新闻类tdk配置
     */
    @ApiOperation("日本看病新闻类tdk配置")
    @RequiresPermissions("ydz:otherNews:tdkSet")
    @GetMapping("/tdkEdit")
    public String tdkEdit()
    {
        return prefix + "/tdkSet";
    }

    /**
     * 获取获取每日药闻视图
     *
     * @return List<Drug>
     */
    @ApiOperation("获取每日药闻视图")
    @GetMapping("/getNewsDayView")
    @ResponseBody
    public AjaxResult getNewsDayView()
    {
        return otherNewsService.getNewsDayView();
    }

    /**
     * 获取 首页-医药前沿，临床招募，远程问诊，健康护理
     *
     * @return List<Drug>
     */
    @ApiOperation("获取 首页-医药前沿，临床招募，远程问诊，健康护理")
    @GetMapping("/getOtherNewsByTypeView")
    @ResponseBody
    public AjaxResult getOtherNewsByTypeView()
    {
        return otherNewsService.getOtherNewsByTypeView();
    }


    /**
     * 获取 首页-安全用药
     *
     * @return 其他新闻类集合
     */
    @ApiOperation("获取 首页-安全用药")
    @GetMapping("/getOtherNewsAQYY")
    @ResponseBody
    public AjaxResult getOtherNewsAQYY(){
        return otherNewsService.getOtherNewsAQYY();
    }

    /*
     * 根据其他新闻id查询上一篇下一篇
     * */
    @GetMapping("/getUpandDown/{id}")
    @ResponseBody
    public AjaxResult getUpandDown(@PathVariable("id") Long id){
        return otherNewsService.getUpandDown(id);
    }

    /*
     * 增加浏览啦
     * */
    @GetMapping("/updateotherNewsBrowseNum/{id}")
    @ResponseBody
    public void updateotherNewsBrowseNum(@PathVariable("id") Long id){
        otherNewsService.updateotherNewsBrowseNum(id);
    }

}
